package com.readboottest.service.impl;

import com.readboottest.entity.Bookmark;
import com.readboottest.mapper.BookmarkMapper;
import com.readboottest.service.BookmarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author simaduoduo
 * @date 2019/7/25 13:51
 * @desc 书签处理接口实现类
 */
@Service
public class BookmarkServiceImpl implements BookmarkService {
    @Autowired
    private BookmarkMapper bookmarkMapper;
    @Override
    public int addBookmark(Bookmark bookmark) {
        /**
         * 用户书签数量不得超过5个
         */
        if(bookmarkMapper.selectBookmarkNumberByUserId(bookmark.getUserId())>=5){
            return -1;
        }else {
            return bookmarkMapper.insertBookmark(bookmark);
        }
    }

    @Override
    public int removeBookmark(int id) {
        return bookmarkMapper.deleteBookmark(id);
    }

    @Override
    public int updateBookmark(Bookmark bookmark) {
        return bookmarkMapper.updateBookmark(bookmark);
    }

    @Override
    public List<Bookmark> queryBookmarks(int userId) {
        return bookmarkMapper.selectBookmarksByUserId(userId);
    }

    public BookmarkMapper getBookmarkMapper() {
        return bookmarkMapper;
    }

    public void setBookmarkMapper(BookmarkMapper bookmarkMapper) {
        this.bookmarkMapper = bookmarkMapper;
    }
}
